/**
 * @fileoverview
 * JavaScript Object Template toSource() implementations.
 * @author Hedger Wang (hedgerwang@gmail.com)
 */

// Still Under developement, please don't use it. 

/**
 * @param {String|number} content
 * @return {string}
 */
Jot.toAddSource_ = function(content) {
  return ['.add(\'', content
      .replace(/[\n\r]/g, '\\n')
      .replace(/'/g, '\\\'') ,
    '\')\n'].join('');
};

/**
 * @param {String|number} content
 * @return {string}
 */
Jot.toEachSource_ = function(condition) {
  if (!condition) {
    return '.each()\n';
  }
  return ['.each(\'', condition , '\')\n'].join('');
};


/**
 * @public
 * @return {string}
 */
Jot.prototype.toSource = function() {
  var contents = this.contents_;
  // console.log(this.contents_);

  var output = [];
  for (var i = 0,j = contents.length; i < j; i++) {
    var content = contents[i];
    switch (Jot.typeOf(content)) {
      case 'string':;
        output.push(Jot.toAddSource_(content));
        break;

      case 'number':
        output.push(Jot.toAddSource_(content));
        break;

      case 'object':
        if (content instanceof Jot.StringRenderer_) {
          output.push(content.data_);
        } else if (content instanceof Jot.BooleanRenderer_) {
          output.push('::boolean');
        } else if (content instanceof Jot.EachRenderer_) {
          output.push(content.toSource());
        } else {
        }
        break;

      default:;
        alert(4);
        break;

    }
  }
  return output.join('');
};


/**
 * @return {string
 **/
Jot.EachRenderer_.prototype.toSource = function() {
  return Jot.toEachSource_(this.data_);
};